<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use App\Traits\WorkerRequest;
use App\Traits\UserToken;
use App\Traits\MessageInitParam;
use App\Traits\MessageHandles;
use Illuminate\Http\Request;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, WorkerRequest, UserToken, MessageInitParam, MessageHandles;

    public function __construct(Request $request)
    {
        $data = $request->all();
        self::$client_id = isset($data['client_id'])?$data['client_id']:'';//客户端client_id
        if(self::$client_id) {
            self::$request = isset($data['message'])?$data['message']:[];//接受所有参数
        } else {
            self::$request = $data;
        }
        self::$f = isset(self::$request['f'])?self::$request['f']:'';//默认方法
        self::init();//数据资源加载
    }

    /**
     * 需要获取的数据资源
     */
    public static function init()
    {
        self::allXianhong();//所有限红
        self::requestParam(self::$request);//初始化参数
    }

    /**
     * 刷新用户数据
     * @param array $userData
     */
    public function flushUserData($userData = [])
    {
        self::bindUserData($userData);
        self::updateUserData($userData);
    }

    /**
     * 无返回值设置
     */
    public function __destruct()
    {
        return response()->json([],404);
    }
}
